using NUnit.Framework;

namespace ValidationFramework.FieldValidationManagerTests
{
    [TestFixture]
    public class InheritanceTests
    {

        public class BaseClass
        {
            [RequiredStringRule] public string field1;
        }

        public class InheritedClass : BaseClass
        {
            [RequiredStringRule] public string field2;
        }

        [Test]
        public void InstanceValidate()
        {
            var baseClass = new BaseClass();
            var baseClassFieldValidationManager = ValidationManagerFactory.GetFieldValidationManager(baseClass);
            baseClassFieldValidationManager.ValidateAll();
            Assert.AreEqual(1, baseClassFieldValidationManager.ValidatorResultsInError.Count);

            var inheritedClass = new InheritedClass();
            var inheritedClassFieldValidationManager = ValidationManagerFactory.GetFieldValidationManager(inheritedClass);
            inheritedClassFieldValidationManager.ValidateAll();
            Assert.AreEqual(2, inheritedClassFieldValidationManager.ValidatorResultsInError.Count);
        }


        [Test]
        public void StaticValidate()
        {
            var baseClass = new BaseClass();
            var validationErrors = FieldValidationManager.ValidateAll(baseClass, null, null);
            Assert.AreEqual(1, validationErrors.Count);

            var inheritedClass = new InheritedClass();
            var inheritedClassValidationErrors = FieldValidationManager.ValidateAll(inheritedClass, null, null);
            Assert.AreEqual(2, inheritedClassValidationErrors.Count);
        }
    }
}
